package com.assistant.core.modules.sys.adapter;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.List;

@Configuration
public class AssistantWebConfig implements WebMvcConfigurer {

    @Bean
    public AssistantLoginInterceptor getSupplierLoginInterceptor() {
        return new AssistantLoginInterceptor();
    }

    @Bean
    public OperatorHandlerMethodArgumentResolver getOperatorHandlerMethodArgumentResolver() {
        return new OperatorHandlerMethodArgumentResolver();
    }

    @Override
    public void addArgumentResolvers(List<HandlerMethodArgumentResolver> resolvers) {
        resolvers.add(getOperatorHandlerMethodArgumentResolver());
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(getSupplierLoginInterceptor()).addPathPatterns("/**").excludePathPatterns("/**/login");
        WebMvcConfigurer.super.addInterceptors(registry);
    }
}
